#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(int argc, char const *argv[])
{
    
    int pid= fork();
    if(pid==0)
    { // 子进程执行  ping 
        printf("child process pid=%d\n",getpid());
        char *cmd=  "/usr/bin/ping";
        char *args[]={"ping","-c","5","www.baidu.com",NULL};
        char *envp[]={NULL};
        int ret= execve(cmd,args,envp);
        if(ret==-1)
        {
            perror("execve");
            return -1;

        }
        printf("child process exit\n"); // 子进程执行成功，不会执行下面的代码
    }else{
        printf("parent process pid=%d\n",getpid());
        waitpid(pid,NULL,0);
        printf("parent process exit\n");
    }

    return 0;
}
